import { RepairOrderParts } from 'src/services/type';
import { useVersionStore } from 'src/stores/versionStore';

export function getStatusColor(status: string) {
  if (status == '') {
    return;
  }
  if (status == 'Not Complete') {
    return 'not-complete';
  }
  if (status == 'All Pass') {
    return 'pass';
  }
  if (status == 'COMPLETE*') {
    return 'FORCE_COMPLETE';
  }
  if (status) {
    return `${status}`;
  }
}

const versionStore = useVersionStore();

export function getPartsStatus(
  serial_no: string,
  stock_code: string,
  sw_ver: string,
  hw_ver: string
) {
  let status = ''
  if (serial_no == '') {
    status += 'missing'
    return status
    // return getOrderStatusColor('missing');
  }
    
    if (sw_ver){
      const sw_msg = versionStore.getSwStatusClass(stock_code, sw_ver);
      status += `sw-${sw_msg}`
      // return `version-${sw_msg}`
    }
    if (hw_ver) {
      const hw_msg = versionStore.getHwStatusClass(stock_code, hw_ver);
      status += `,hw-${hw_msg}`
    }
    return status
  
}

export function getOrderStatusColor(status: string) {
  // console.log(status);
  
  if (status == '') {
    return;
  }
  if (status) {
    if (status == 'CHECKED IN') {
      return 'checked-in';
    }
    if (status == 'COMPLETE') {
      return status;
    }
    if (status == 'COMPLETE*') {
      return 'FORCE_COMPLETE';
    }
    return status;
  }
}

export function getHardTimeReplacementStatus(next: string) {
  console.log(next);

  if (next) {
    const monthsDiff = getHardTimeDiff(next);
    if (monthsDiff <= 3 && monthsDiff > 0) {
      return 'urgent';
    }
    if (monthsDiff <= 6 && monthsDiff > 0) {
      return 'warning';
    }
  }
}

export function getHardTimeDiff(next: string) {
  const nextDate = new Date(next);
  const nowDate = new Date();
  const monthsDiff =
    (nextDate.getFullYear() - nowDate.getFullYear()) * 12 +
    (nextDate.getMonth() - nowDate.getMonth());
  return monthsDiff;
}

export function checkDiff(diff: number) {
  console.log(diff);
  if (diff >= 0) {
    return `${diff} months left`;
  }
  if (diff < 0) {
    diff = Math.abs(diff);

    return `${diff} months have passed`;
  }
}
